<template>
  <div class="welcome w">
<!--    <div class="w">-->
      <h1>在线编程笔试平台</h1>
      <el-collapse style="margin: 40px auto 0; width: 80%; font-size: 16px">
        <el-collapse-item title="小组成员" style="padding:0 20px">
          <div>组长：林泽铭</div>
          <div>组员：张海佳，李子恺，陈育铿</div>
        </el-collapse-item>
        <el-collapse-item title="使用环境" style="padding:0 20px">
          <div>前端：Vue</div>
          <div>中间数据传递:axios</div>
          <div>后端：Express</div>
        </el-collapse-item>
      </el-collapse>
<!--    </div>-->

    <div v-show="isLogin" style="margin-top: 40px">
      <button @click="jump_to_interview" v-if="!identity">
        创建面试页面
      </button>
      <el-input v-model="input" placeholder="请输入八位邀请码" id="eInput"></el-input>
      <button @click="jump_to_room" style="margin-top: 10px">
        进入面试房间
      </button>
    </div>

  <div v-show="!isLogin" style="margin-top: 40px">
    您尚未登录，请先登录
  </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import axios from "axios";
import qs from "qs";
import { Message } from "element-ui";
import { mapMutations } from 'vuex'
export default {
  name: "Welcome",
  components: {},
  computed: {

   ...mapGetters(["isLogin"]),
    ...mapGetters(["currentUser"]),
    ...mapGetters(["email"]),
    ...mapGetters(["userImage"]),
    ...mapGetters(["identity"])
  },
  data() {
    return {
      input: ""
    };
  },
  mounted() {

  },
  methods: {
     async jump_to_room() {
       if(this.input.length<8)
       {
         Message.error("邀请码不符合要求");
       }
       else {
         await axios({
           method: "post",
           url: "/room/get_questions",
           data:
             qs.stringify(
               {
                 RID: this.input,
               })
         })
           .then(res => {
             //获取数据
             if(res.data.err === 0)
             {
               if(this.identity==0)
               {
                 this.$router.push({path:'/interviewer_room',query: {RID:this.input}});
               }
               else {
                 this.$router.push({path:'/interviewee_room',query: {RID:this.input}});
               }

             }
             else if (res.data.err === -3) {
               Message.error("房间不存在")
             }
           })
           .catch(function(error) {
             console.log(error);
           });

       }


     },
    jump_to_interview() {
          this.$router.push("/interview");



      }
    }

};

</script>

<style>
@import "../../common/stylus/style.css";
@import "../../assets/css/all.css";
@import "../../assets/css/welcome.css";
</style>